﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infragistics.WebUI.WebControls;

namespace IGMVC.Web.Helpers
{
    internal class ControlPreset
    {
        /// <remarks>
        /// JAC: 
        /// Because they are related to Views (as well as a shared resource)
        /// the presets should probably go under the ~/Views/Shared/[whatever] folder.  
        /// The name "ig_Presets" is totally arbitrary.
        /// </remarks>
        public const string DefaultPresetPath = "~/Views/Shared/ig_Presets";


        private readonly string _name;


        public ControlPreset()
        {
        }
        public ControlPreset(string name)
        {
            this._name = name;
        }


        public void LoadInto(WebControlBase control)
        {
            control.LoadPreset(GetFilePath(), true);
        }

        public virtual string GetFilePath()
        {
            var presetName = this._name;

            if (string.IsNullOrEmpty(presetName))
                presetName = "default";

            var relativePath = string.Format("{0}/{1}.xml", DefaultPresetPath, presetName);
            return HttpContext.Current.Server.MapPath(relativePath);
        }
    }
}
